<template>
	<view>
		<view class="tixian-s">
			<view>转账类型：</view>
			<view class="tixian-wx">
				<picker class="tixian-ri" @change="bindPickerChange" :value="index" :range="array">
					<view class="uni-input"><view>{{array[index]}}</view><image class="next-icon" style="width:30rpx" src="/static/other/next.png" mode="widthFix"></image></view>
				</picker>
			</view>
		</view>
		<view class="tixian-price">
			<view class="tixian-input">
				<view>账户：</view>
				<input type="text"  v-model="zhanghao" placeholder="输入账户" placeholder-style="font-size:30rpx;color:#999">
			</view>
			<view class="tixian-input"  v-if="index==0">
				<view>转账积分 ：</view>
				<input type="number" v-model="price" placeholder="输入转账积分" placeholder-style="font-size:30rpx;color:#999">
			</view>
			<view class="tixian-input"  v-if="index==1">
				<view>转账佣金 ：</view>
				<input type="number" v-model="price" placeholder="输入转账佣金" placeholder-style="font-size:30rpx;color:#999">
			</view>
			<view class="tixian-tip" v-if="index==0">
				<view class="tx-tip">可转账积分{{jifen}}</view>
				<view class="tx-all" @click="jifenalltx">全部转账</view>
			</view>
			<view class="tixian-tip" v-if="index==1">
				<view class="tx-tip">可转账佣金￥{{allpric}}</view>
				<view class="tx-all" @click="allpricalltx">全部转账</view>
			</view>
		</view>
		<view class="tx-btn" @click="cash">确认转账</view>
	</view>
</template>
<script>
	import api from "@/common/fxb.js"
	export default {
		data() {
			return {
				price:'', //输入金额
				allpric:0 , //可提现金额
				array: ["积分转账","佣金转账"],
				index:0,
				zhanghao:'',
				jifen:'',//可提现积分
			};
		},
		onLoad() {
			this.getdata();
		},
		methods:{
			allpricalltx:function(){
				this.price = this.allpric
			},
			jifenalltx:function(){
				this.price = this.jifen
			},
			cash:function(){
				var that = this;
				if(that.zhanghao==''){
					uni.showToast({
						title:"请输入账户",
						icon:'none'
					})
					return false 
				}
				if(that.price==''){
					uni.showToast({
						title:"请输入转账金额",
						icon:'none'
					})
					return false 
				}
				uni.showModal({
				    title: '确认转账吗？',
				    success: function (res) {
				        if (res.confirm) {
				            if(that.index==0){
				            	that.global.request.post({
				            		data: {
				            			op:'jifen',
				            			do: 'zhuanzhang',
				            			phone:that.zhanghao,
				            			nums:that.price
				            		},
				            		success: res => {
				            			that.getdata()
				            		}
				            	})
				            }
				            if(that.index==1){
				            	that.global.request.post({
				            		data: {
				            			op:'money',
				            			do: 'zhuanzhang',
				            			phone:that.zhanghao,
				            			nums:that.price
				            		},
				            		success: res => {
				            			that.getdata()
				            		}
				            	})
				            }
				        } else if (res.cancel) {
				            console.log('用户点击取消');
				        }
				    }
				});
			},
			getdata:function(){
				var that = this;
				api.ApiGet({
					op:'',
					do:'tixian',
				},function(res){ 
					that.allpric = res.data.datas.user_info.money;
					that.jifen = res.data.datas.user_info.jifen;
				})
			},
			tixianr:function(){
				uni.navigateTo({
					url:'/pages/tixian-record/tixian-record'
				})
			},
			bindPickerChange: function(e) {
					console.log('picker发送选择改变，携带值为', e.target.value)
					this.index = e.target.value
					this.price = ''
			},
		}
		
	}
</script>

<style lang="scss" scoped>
		page{background-color: $uni-bg;}
		.tixian-s{
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding:20rpx 30rpx;
			background-color: #fff;
			font-size: 30rpx;
			color: #333;
			.tixian-wx{
				display: flex;
				width: 75%;
				justify-content: flex-end;
				.tixian-ri{
					
					display: flex;
					justify-content: flex-end;
					float: left;
				}
				view{
					float: left;
					font-size: 28upx;
					color: #999;
				}
				image{
					width: 40upx;
					height: 40upx;
					margin-left: 12upx;
				}
				
			}
		}
		.uni-input{
			display: flex;
			align-items: center; 
		}
		.next-icon{
			width: 20upx; 
		}
		.tixian-price{
			background-color: #fff;
			.tixian-tit{
				margin-bottom: 15upx;
				font-size: 30rpx;
				color: #333;
			}
			.tixian-input{
				display: flex;
				align-items: center;
				padding: 20upx 30rpx;
				view{
					font-size: 30rpx;
					color: #333;
					width: 180upx;
				}
				input{
					margin-left: 50upx;
					font-size: 30rpx;
					color: #FE6806;
				}
			}
			.tixian-tip{
				display: flex;
				padding: 20rpx 30rpx;
				font-size: 28upx;
				color: #8c8c8c;
				.tx-all{
					margin-left: 30rpx;
					color: #007AFF;
				}
			}
		}
		.tx-jl{
			width: 690upx;
			padding:20upx 30rpx;
			font-size: 30rpx;
			color:#FE6806 ;
			text-align: right;
		}
		.tx-btn{
			width: 500upx;
			height: 88upx;
			margin: 80upx 135upx;
			background: linear-gradient(90deg,#FF9C27,#FD6913);
			box-shadow: 0 0 16upx rgba($color: #FF9C27, $alpha: .4);
			border-radius: 80upx;
			font-size: 30rpx;
			color: #fff;
			text-align: center;
			line-height: 88upx;
		}
</style>
